#include<bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;
const int maxn = 1e5;

struct node {
	int point, dis;
	bool operator < (const node &x) const {
		return dis > x.dis;
	}
};


int dist[maxn + 5];		// dist[i] : distance from beginPoint to i
vector<pii> edge[maxn + 5];		// edge[i] : array of pii, first = toPoint, second = distance from i to toPoint
priority_queue<node> q;		// find node which has min distance
bool vis[maxn + 5];

int path[maxn + 5];		// path[i] : pre point of No.i point


inline void dijkstra(int s) {
	memset(dist, 0x3f, sizeof(dist));
	dist[s] = 0;
	q.push({s, 0});
	path[s] = -1;

	while (!q.empty()) {
		node t = q.top();
		q.pop();

		if (vis[t.point]) continue;
		vis[t.point] = 1;

		for (auto ii : edge[t.point]) {
			int tmp = dist[t.point] + ii.second;

			if (dist[ii.first] > tmp) {
				dist[ii.first] = tmp;
				path[ii.first] = t.point;

				if (!vis[ii.first])
					q.push({ii.first, dist[ii.first]});
			}
		}
	}
}

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n, m, s, t, l, base;		// n node, m edge, s beginPoint, t endPoint
	cin >> n >> m >> l >> base;

	s = 1, t = n;

	int x, y, z, zz;
	for (int i = 1; i <= m; i++) {
		cin >> x >> y >> z >> zz;
		edge[x].push_back({y, zz});
	}

	dijkstra(s);

	cout << dist[t];
	return 0;
}
